define(function (require, exports, module) {
    var angular = require("angular");
    var ui = require('ui');
    var util = require('util');
    require("angular-ui");
    var common = require("./common");
    var api_prefix = G_CONFIG["api_prefix"] + "/qmyx/para-setting/"; //api前缀

    angular.module('PublicRegistrationReview', [])
        .controller('RegistrationReviewController', ['$scope', '$http', function ($scope, $http) {
            $scope.save = function () {
                var data = $scope.data;
                $http.post(
                        api_prefix + "save-reg-audit",
                    {
                        orgBrokerAutoAudit: data.agencyregisterautocheck,
                        brokerAutoAudit: data.regisautocheck,
                        regLoginSms: data.isSms.regLogin.iseable,
                        regLoginTem: data.isSms.regLogin.template,
                        forgetTem: data.isSms.forget.template,
                        brokerRegSms: data.brokerRegRemind.IsEnable,
                        smsId: data.brokerRegRemind.id,
                        mobile: data.brokerRegRemind.Mobiles.join(';') + ";",
                        startTime: $scope.startTimeHour + ':' + $scope.startTimeMinute,
                        endTime: $scope.endTimeHour + ':' + $scope.endTimeMinute
                    }
                )
                    .success(function () {
                        ui.showSucTip();
                    })
            };
            //添加手机号
            $scope.addTel = function () {
                common.showMobileInputDialog({
                    ok: function (mobile) {
                        var data = $scope.data;
                        $http.post(
                                api_prefix + "add-reg-remind",
                            {
                                id: data.brokerRegRemind.id,
                                mobile: mobile
                            }
                        )
                            .success(function (res) {
                                if (res.retCode == 0) {
                                    data.brokerRegRemind.Mobiles.push(mobile);
                                    ui.showSucTip();
                                }
                            });
                    }
                });
            };
            //删除短信注册提醒
            $scope.delTel = function (mobile, index) {
                util.confirm("您确定要删除吗？", {
                    ok: function () {
                        var data = $scope.data;
                        $http.post(
                                api_prefix + "del-reg-remind",
                            {
                                type: 0,
                                mobile: mobile
                            }
                        )
                            .success(function (res) {
                                if (res.retCode == 0) {
                                    data.brokerRegRemind.Mobiles.splice(index, 1);
                                    ui.showSucTip();
                                }
                            });
                    }
                });
            };

            $http.get(api_prefix + "get-reg-audit")
                .then(function (res) {
                    var data = res.data.data;

                    //机构经纪人注册自动审核
                    var agencyRegisterAutoCheck = data.agencyregisterautocheck;
                    ui.initSwitch('#agencyregister_autocheck', function (data) {
                        $scope.data.agencyregisterautocheck = data.value;
                    });
                    if (agencyRegisterAutoCheck == '1') {
                        ui.openSwitch("agencyregister_autocheck");
                    }
                    else {
                        ui.offSwitch("agencyregister_autocheck");
                    }
                    //经纪人注册自动审核
                    var registAutoCheck = data.regisautocheck;
                    ui.initSwitch('#regist_autocheck', function (data) {
                        $scope.data.regisautocheck = data.value;
                    });
                    if (registAutoCheck == '1') {
                        ui.openSwitch("regist_autocheck");
                    }
                    else {
                        ui.offSwitch("regist_autocheck");
                    }
                    //注册/登录短信验证
                    var isSmsRegLogin = data.isSms.regLogin;

                    ui.initSwitch('#reg_sms', function (data) {
                        $scope.data.isSms.regLogin.iseable = data.value;
                        $scope.$applyAsync();
                    });
                    if (isSmsRegLogin.iseable == 1) {
                        ui.openSwitch("reg_sms");
                    }
                    else {
                        ui.offSwitch("reg_sms");
                    }
                    //新经纪人注册提醒短信
                    var brokerRegRemind = data.brokerRegRemind;
                    ui.initSwitch('#broker_reg_remind', function (data) {
                        $scope.data.brokerRegRemind.IsEnable = data.value;
                        $scope.$applyAsync();
                    });
                    if (brokerRegRemind.IsEnable == '1') {
                        ui.openSwitch('broker_reg_remind');

                    } else {
                        ui.offSwitch('broker_reg_remind');
                    }

                    var hours = [];
                    for (var i = 0; i < 24; i++) {
                        hours.push(util.pad(i, 2));
                    }
                    $scope.hours = hours;
                    $scope.minutes = ['00', '10', '20', '30', '40', '50', '59'];

                    //发送时间段
                    var split = brokerRegRemind.StartTime.split(':');
                    $scope.startTimeHour = split[0];
                    $scope.startTimeMinute = split[1];

                    split = brokerRegRemind.EndTime.split(':');
                    $scope.endTimeHour = split[0];
                    $scope.endTimeMinute = split[1];

                    var mobiles = brokerRegRemind.Mobiles;
                    mobiles = mobiles.replace(/;$/, '');
                    if (mobiles == "") {
                        brokerRegRemind.Mobiles = [];
                    }
                    else {
                        brokerRegRemind.Mobiles = mobiles.split(';');
                    }

                    $scope.data = data;

                })

        }])
});